﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SlamDunk.MES.Domain.Entities.DefinitionContext;

namespace SlamDunk.MES.Repository.EntityConfigurations.DefinitionContext
{
    /// <summary>
    /// 物料清单实体映射配置
    /// </summary>
    public class BomConfig : IEntityTypeConfiguration<Bom>
    {
        /// <summary>
        /// 配置
        /// </summary>
        public void Configure(EntityTypeBuilder<Bom> builder)
        {
            //配置属性
            builder.HasKey(bom => bom.Id).IsClustered(false);
            builder.HasMany(bom => bom.Items).WithOne(item => item.Bom).IsRequired().OnDelete(DeleteBehavior.Cascade);
            builder.Property(bom => bom.RunSize).HasPrecision(29, 10);

            //配置索引
            builder.HasIndex(bom => bom.AddedTime).IsUnique(false).IsClustered();
        }
    }
}
